#include "../Http.hpp"
int main()
{
    Socket cli_sock;
    if (!cli_sock.CreateClient(8088, "127.0.0.1")) {
        ERR_LOG("Failed to create client connection");
        return -1;
    }
    
    std::string req = "PUT /1234.txt HTTP/1.1\r\nConnection: keep-alive\r\n";
    std::string body;
    
    // 检查文件大小，避免处理过大的文件
    if (!Util::ReadFile("./hello.txt", body)) {
        ERR_LOG("Failed to read file hello.txt");
        cli_sock.Close();
        return -1;
    }
    
    // 限制文件大小，避免内存问题
    if (body.size() > 1024 * 1024) { // 1MB限制
        ERR_LOG("File too large: %zu bytes", body.size());
        cli_sock.Close();
        return -1;
    }
    
    req += "Content-Length: " + std::to_string(body.size()) + "\r\n\r\n";
    
    if (cli_sock.Send((void *)req.c_str(), req.size()) == -1) {
        ERR_LOG("Failed to send request header");
        cli_sock.Close();
        return -1;
    }
    
    if (cli_sock.Send((void *)body.c_str(), body.size()) == -1) {
        ERR_LOG("Failed to send request body");
        cli_sock.Close();
        return -1;
    }
    
    char buf[1024] = {0};
    ssize_t recv_size = cli_sock.Recv(buf, 1023);
    if (recv_size > 0) {
        DBG_LOG("[%s]", buf);
    } else {
        ERR_LOG("Failed to receive response");
    }
    
    sleep(3);
    cli_sock.Close();
    return 0;
}
